package com.nefu.huiyi.service.impl;

import com.nefu.huiyi.entity.TitleStatistics;
import com.nefu.huiyi.mapper.DoctorTitleMapper;
import com.nefu.huiyi.service.DoctorTitleService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DoctorTitleServiceImpl implements DoctorTitleService {

    private final DoctorTitleMapper doctorTitleMapper;

    public DoctorTitleServiceImpl(DoctorTitleMapper doctorTitleMapper) {
        this.doctorTitleMapper = doctorTitleMapper;
    }

    @Override
    public Map<String, Integer> getTitleDistribution() {
        List<TitleStatistics> statistics = doctorTitleMapper.countDoctorsByTitle();
        return statistics.stream()
                .collect(Collectors.toMap(
                        TitleStatistics::getTitle,
                        TitleStatistics::getCount
                ));
    }

    @Override
    public List<TitleStatistics> getTitleStatistics() {
        return doctorTitleMapper.countDoctorsByTitle();
    }
}
